<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="views/include :: header('系统配置')"/>
    <!-- 注意， 只需要引用 JS，无需引用任何 CSS ！！！-->
    <script th:src="@{/plugins/wangEditor/release/wangEditor.min.js}"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form id="add_Pic_Form" lay-filter="add_Pic_Form" class="layui-form" enctype="multipart/form-data">
            <div class="layui-form layuimini-form">
                <div class="layui-form-item">
                    <label class="layui-form-label required">标题</label>
                    <div class="layui-input-block">
                        <input type="text" th:name="title" lay-verify="required" lay-reqtext="标题不能为空"
                               placeholder="请输入标题名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">bug详情</label>
                    <div class="layui-input-block">
                        <div id="editor" th:name="content">
                            <p>请输入您要反馈的问题详情</p>
                        </div>
                    </div>
                </div>
                <input type="hidden" name="content" id="content" >

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        var E = window.wangEditor;
        var editor = new E('#editor');
        // 或者 var editor = new E( document.getElementById('editor') )
        // 配置服务器端地址
        editor.customConfig.uploadFileName = 'file';
        editor.customConfig.uploadImgServer = '/FileUpload/wangEditorUpload';
        editor.create();
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var formData = new FormData(document.getElementById("add_Pic_Form"));
            console.log(formData);
            console.log(data.field);
            $("#content").val(editor.txt.html());
            // var ss =editor.txt.html();
            // $("#contentHtml").val(editor.txt.html());
            $.ajax({
                url: "/question/editQuestion",
                data: {"title":data.field.title,"content":editor.txt.html()},
                type: "post",
                //4.接收后台修改响应回来的数据；关闭弹出层、提示修改信息、刷新table
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {
                            offset: '15px',
                            icon: 6,
                            time: 2000
                        }, function () {
                            window.location.href = '/question/toQuestionList';
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 2000
                        });
                    }
                }
            });
            return false;//阻止跳转；
        });
    });
</script>
</body>
</html>